<template>
  <div class="page-box">
    <el-card class="page-box-card">
      <el-form :model="queryParams" ref="queryForm" size="small" label-width="128px" inline @submit.native.prevent>
        <!-- <el-form-item label="身份证号" prop="param.idCard">
          <el-input v-model="queryParams.param.idCard" placeholder="请输入身份证号" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item> -->
        <el-form-item label="就诊流水号" prop="jzlsh">
          <el-input style="width: 200px" v-model="queryParams.param.jzlsh" placeholder="请输入就诊流水号"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="param.name">
          <el-input v-model="queryParams.param.name" placeholder="请输入姓名" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <!-- <el-form-item label="档案状态" prop="param.archivesType">
          <el-select
            style="width: 240px"
            clearable
            v-model="queryParams.param.archivesType"
            placeholder="请选择档案状态"
          >
            <el-option label="未提交" value="0"> </el-option>
            <el-option label="已提交" value="1"> </el-option>
            <el-option label="已审核" value="2"> </el-option>
            <el-option label="已驳回" value="3"> </el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="档案号" prop="param.fileNum">
          <el-input
            v-model="queryParams.param.fileNum"
            placeholder="请输入档案号"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item> -->
        <!-- <el-form-item label="所属项目" prop="param.projectId">
          <el-select
            style="width: 240px"
            clearable
            v-model="queryParams.param.projectId"
            placeholder="请选择所属项目"
          >
            <el-option v-for="item in projectList" :key="item.id" :label="item.topicShortName" :value="item.id"> </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="所属科室" prop="param.departmentId">
          <el-input v-model="queryParams.param.departmentId" placeholder="请输入所属科室" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <!-- <el-form-item label="数据来源" prop="param.source">
          <el-select
            style="width: 240px"
            v-model="queryParams.param.source"
            placeholder="请选择数据来源"
          >
            <el-option
              v-for="item in dict.type.data_source"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="治疗类型" prop="param.treatmentTypes">
          <el-select
            style="width: 240px"
            filterable
            v-model="queryParams.param.treatmentTypes"
            placeholder="请选择治疗类型"
            multiple
            clearable
          >
            <el-option label="AIS静脉溶栓" value="AIS静脉溶栓"> </el-option>
            <el-option label="AIS介入再通" value="AIS介入再通"> </el-option>
            <el-option label="脑出血" value="脑出血"> </el-option>
            <el-option label="颅内动脉瘤" value="颅内动脉瘤"> </el-option>
            <el-option label="CES/CAS" value="CES/CAS"> </el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="手术方式" filterable v-if="queryParams.param.treatmentTypes" prop="param.operationWay">
          <el-select style="width: 240px" v-model="queryParams.param.operationWay" placeholder="请选择手术方式" multiple>
            <el-option :disabled="judge('0')" label="溶栓" value="0">
            </el-option>
            <el-option :disabled="judge('1')" label="桥接" value="1">
            </el-option>
            <el-option :disabled="judge('2')" label="AIS介入再通" value="2">
            </el-option>
            <el-option :disabled="judge('3')" label="开颅血肿清除术" value="3">
            </el-option>
            <el-option :disabled="judge('4')" label="去骨瓣减压术脑室镜下血肿抽吸术" value="4">
            </el-option>
            <el-option :disabled="judge('5')" label="钻孔血肿抽吸术" value="5">
            </el-option>
            <el-option :disabled="judge('6')" label="复合手术" value="6">
            </el-option>
            <el-option :disabled="judge('7')" label="其他" value="7">
            </el-option>
            <el-option :disabled="judge('8')" label="接入栓塞术" value="8">
            </el-option>
            <el-option :disabled="judge('9')" label="闭夹术" value="9">
            </el-option>
            <el-option :disabled="judge('10')" label="标准式CEA" value="10">
            </el-option>
            <el-option :disabled="judge('11')" label="外翻式CEA" value="11">
            </el-option>
            <el-option :disabled="judge('12')" label="CAS" value="12">
            </el-option>
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="手术操作标化名称" prop="param.operationName">
          <el-input v-model="queryParams.param.operationName" placeholder="请输入手术操作标化名称" clearable style="width: 240px"
            @keyup.enter.native="handleQuery" /> -->
        <!-- <el-select
            style="width: 240px"
            filterable
            v-model="queryParams.param.operationName"
            placeholder="请选择手术操作标化名称"
            multiple
          >
            <el-option label="急性脑梗死介入再通" value="0"> </el-option>
            <el-option label="脑出血开颅血肿清除" value="1"> </el-option>
            <el-option label="脑出血穿刺引流" value="2"> </el-option>
            <el-option label="动脉瘤开颅" value="3"> </el-option>
            <el-option label="动脉瘤栓塞" value="4"> </el-option>
            <el-option label="颈动脉支架" value="5"> </el-option>
            <el-option label="颈动脉内膜剥脱" value="6"> </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="诊断名称" prop="param.zzmc">
          <el-input
            v-model="queryParams.param.zzmc"
            placeholder="请输入诊断名称"
            clearable
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
          <!-- <el-select
            style="width: 240px"
            v-model="queryParams.param.zzbm"
            placeholder="请选择诊断编码"
            multiple
            :multiple-limit="4"
            clearable
          >
            <el-option label="脑卒中，未特指为出血或梗死" value="I64">
            </el-option>
            <el-option label="入脑前动脉的闭塞或狭窄，未造成脑梗死" value="I65">
            </el-option>
            <el-option label="大脑动脉的闭塞和狭窄，未造成脑梗死" value="I66">
            </el-option>
            <el-option label="其它脑血管病、急性动脉瘤" value="I67">
            </el-option>
            <el-option label="分类于他处的疾病引起的脑血管疾患" value="I68">
            </el-option>
            <el-option
              label="中高危风险患者预防静脉血栓栓塞"
              value="I82.900x004"
            >
            </el-option>
            <el-option label="脑梗死" value="I63"> </el-option>
            <el-option label="短暂性脑缺血发作（TIA）" value="G45.900x001">
            </el-option>
            <el-option label="脑内出血" value="I61"> </el-option>
            <el-option label="蛛网膜下腔出血" value="I60"> </el-option>
            <el-option
              label="大脑静脉血栓形成引起的脑梗死，非生脓性"
              value="I63.600"
            >
            </el-option>
            <el-option label="化脓性海绵窦血栓形成" value="G08.x00x006">
            </el-option>
            <el-option label="产褥期大脑静脉窦血栓形成" value="O87.301">
            </el-option>
            <el-option label="化脓性乙状窦血栓形成" value="G08.x00x003">
            </el-option>
            <el-option label="化脓性横窦血栓形成" value="G08.x00x009">
            </el-option>
            <el-option label="侧窦栓塞" value="G08.x00x010"> </el-option>
            <el-option label="椎-基底动脉盗血综合征" value="G45.003">
            </el-option>
            <el-option label="锁骨下动脉盗血综合征" value="G45.801">
            </el-option>
            <el-option label="颈内动脉供血不足" value="G45.101"> </el-option>
            <el-option label="颈动脉闭塞综合征" value="G45.102"> </el-option>
            <el-option label="脑淀粉样脑血管病（CAA）" value="E85.400x027">
            </el-option>
            <el-option label="脑血管畸形" value="Q28.300x001"> </el-option>
            <el-option
              label="伴皮层下梗死和白质脑病的常隐性脑动脉病（CARASIL）"
              value="I67.8"
            >
            </el-option>
            <el-option
              label="伴皮层下梗死和白质脑病的常染色体显性遗传性脑动脉病(CADASIL)"
              value="I67.800x012"
            >
            </el-option>
            <el-option
              label="法布里病（FabryDisease）"
              value="E75.200x023 E75.205"
            >
            </el-option>
            <el-option
              label="线粒体脑肌病伴高乳酸血症和卒中样发作综合征（MELAS）"
              value="G71.300x001"
            >
            </el-option>
            <el-option label="血管性痴呆" value="F01.900"> </el-option>
            <el-option label="皮层下血管性痴呆" value="F01.200"> </el-option>
            <el-option label="混合型皮层和皮层下血管性痴呆" value="F01.300">
            </el-option>
            <el-option label="血管性痴呆，其他的" value="F01.800"> </el-option>
            <el-option label="出血性痴呆" value="F01.800x001"> </el-option>
            <el-option label="初发性或维持性睡眠障碍［失眠症］" value="G47.000">
            </el-option>
            <el-option label="日节律性睡眠障碍" value="G47.200x003">
            </el-option>
            <el-option label="睡眠障碍,其他的" value="G47.800"> </el-option>
            <el-option label="睡眠障碍" value="G47.900"> </el-option>
            <el-option label="血管性帕金森综合征" value="G21.400"> </el-option>
          </el-select> -->
        <!-- </el-form-item> -->
        <!-- <SearchCondition
          v-for="item in queryParams.param.recordDtoList"
          :key="item.code"
          :code="item.code"
          :service="true"
          v-model="item.answer"
        /> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-edit" size="mini" :disabled="single"
            @click="handleEdit">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
            @click="handleDelete">删除</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-upload2"
            size="mini"
            v-hasPermi="['definition:class:upload']"
            >导入</el-button
          >
        </el-col> -->
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" :disabled="multiple"
            @click="handleExport">导出</el-button>
        </el-col>
      </el-row>
      <el-table :data="dataList" style="width: 100%" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed="left" />
        <el-table-column type="index" label="排序" width="60" fixed="left" />
        <!-- <el-table-column prop="" label="所属项目" width="180">
          <template slot-scope="scope">-</template>
        </el-table-column> -->
        <el-table-column prop="jzlsh" label="就诊流水号" width="180" align="center">
          <!-- <template slot-scope="scope">
            <template v-if="
                scope.row.recordVoList.find((item) => {
                  return item.code == 'ZL-JBXX-ZYH';
                }).answer
              ">
              {{
                scope.row.recordVoList.find((item) => {
                  return item.code == "ZL-JBXX-ZYH";
                }).answer
              }}
            </template>
            <template v-else> - </template>
          </template> -->
        </el-table-column>
        <!-- <el-table-column prop="idCard" label="身份证号" width="180">
        </el-table-column> -->
        <el-table-column prop="name" label="患者姓名" width="100">
          <!-- <template slot-scope="scope">测试</template> -->
        </el-table-column>
        <el-table-column prop="sex" label="性别" width="100">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex - 0" />
          </template>
        </el-table-column>
        <!-- <el-table-column prop="zdmc" label="入院诊断" width="180" />
        <el-table-column prop="zyysmc" label="住院医师" align="center" /> -->
        <el-table-column prop="jzksmc" label="科室名称" align="center" />
        <!-- <el-table-column label="操作" align="center" fixed="right" width="220">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)"
              v-hasPermi="['system:dept:edit']">修改</el-button>
            <el-button size="mini" type="text" style="color: red" icon="el-icon-delete" @click="handleDelete(scope.row)"
              v-hasPermi="['system:dept:edit']">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </el-card>
    <!-- 添加或修改档案 -->
    <el-dialog :title="title" :visible.sync="addDialog" width="1200px" append-to-body>
      <el-form ref="addForm" :model="addForm" :rules="rules" label-width="140px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份证" prop="idCard">
              <el-input v-model="addForm.idCard" placeholder="请输入身份证"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="addForm.name" placeholder="请输入姓名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="addForm.age" placeholder="请输入年龄"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-radio-group v-model="addForm.sex">
                <el-radio :label="0">女</el-radio>
                <el-radio :label="1">男</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <SearchCondition code="JBXX-FIRSTTIME" :service="true" :oldValue="addForm.otherRecord['JBXX-FIRSTTIME']"
              v-model="addForm.otherRecord['JBXX-FIRSTTIME']" />
          </el-col>
          <el-col :span="12">
            <SearchCondition code="JBXX-FIRSTAIDSCPOPE" :service="true"
              :oldValue="addForm.otherRecord['JBXX-FIRSTAIDSCPOPE']"
              v-model="addForm.otherRecord['JBXX-FIRSTAIDSCPOPE']" />
          </el-col>
          <el-col :span="24">
            <SearchCondition code="ZLLX-TYPE" :service="true" :oldValue="addForm.otherRecord['ZLLX-TYPE']"
              v-model="addForm.otherRecord['ZLLX-TYPE']" />
          </el-col>
        </el-row> -->
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="所属项目" prop="projectId">
              <el-select clearable v-model="addForm.projectId" placeholder="请选择所属项目">
                <el-option v-for="item in projectList" :key="item.id" :label="item.topicShortName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数据来源" prop="source">
              <el-select v-model="addForm.source" placeholder="请选择数据来源">
                <el-option v-for="item in dict.type.data_source" :key="item.value" :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-divider content-position="center">档案信息</el-divider>
        <el-row>
          <el-col :span="12" v-for="(item, index) in recordDtoList" :key="item.code">
            <SearchCondition :data="item" v-model="item.answer" :service="false" />
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {
    insertArchives,
    updateArchives,
    deleteArchives,
    queryArchives,
    exportZl,
  } from "@/api/data/archives";
  import {
    listProject,
  } from "@/api/data/topic";
  import {
    Mixins
  } from "../minix/index";
  export default {
    dicts: ["auditing_type", "project_type", "data_source", "sys_user_sex"],
    mixins: [Mixins],
    data() {
      return {
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        selectionData: [],
        queryParams: {
          param: {
            codeList: [
              "JBXX-MZH",
              "JBXX-CZYS-NO",
              "JBXX-FBSJ",
              "JBXX-DY-TIME",
              "ZL-JBXX-ZYH",
              "ZLLX-TYPE",
              "FILES-UNIT",
              "ZL-JBXX-CYRQ",
            ],
            name: "",
            idCard: "",
            recordDtoList: [{
                code: "JBXX-MZH",
                answer: "",
              },
              {
                code: "JBXX-CZYS-NO",
                answer: "",
              },
            ],
            type: "1", // 档案类型(0:筛查； 1:急救； 2:治疗； 3:康复)
            zzmc: "",
            zzbm: [],
            archivesType: null,
            projectId: null,
            source: null,
            treatmentTypes: [],
            operationWay: [],
            fileNum: '',
            operationName: '',
          },
          pageNum: 1,
          pageSize: 10,
        },
        props: {
          checkStrictly: true,
          label: "name",
          value: "id",
        },
        dataList: [],
        total: 0,
        treeData: [],
        title: "",
        addDialog: false,
        addForm: {
          age: "", //	年龄
          bmi: "", //	bmi
          height: "", //	身高
          idCard: "", //	身份证
          name: "", //	姓名
          nation: "", //	民族
          phone: "", //	联系电话
          pinyinFull: "", //	姓名全拼
          pinyinSimple: "", //	姓名简拼
          recordDtoList: [],
          otherRecord: {
            "JBXX-FIRSTTIME": null, // 急救发生时间
            "JBXX-FIRSTAIDSCPOPE": null, // 急救范围
            "ZLLX-TYPE": null, // 治疗类型
            "JBXX-MZH": "", // 门/急诊号 默认传空字符串
            "JBXX-CZYS-NO": "", // 卒中医生编号 默认传空字符串
          },
          remark: "", //	备注
          sex: "", //	性别 1 : 男 ， 0 : 女
          source: "", //	数据来源
          status: "", //	更新标识：0第一次输入，1更新患者信息
          type: "1", //	档案类型(0:筛查； 1:急救； 2:治疗； 3:康复)
          weight: "", //	体重
        },
        rules: {},
        projectList: [],
      };
    },
    created() {
      this.getList();
      this.getProjectList();
      setTimeout(() => {
        this.getRecordDtoList();
      }, 200);
    },
    methods: {
      // 获取数据列表
      getProjectList() {
        const param = {
          pageNum: 1,
          pageSize: 999,
          param: {
            name: "",
          },
        };
        console.log("param: ", param);
        listProject(param).then((response) => {
          this.projectList = [...response.data.list];
          console.log('this.projectList: ', this.projectList);
        });
      },
      judge(type) {
        if (
          this.queryParams.param.treatmentTypes &&
          this.queryParams.param.treatmentTypes.length
        ) {
          if (type == "0" || type == "1") {
            if (
              this.queryParams.param.treatmentTypes.findIndex((item) => {
                return item == "AIS静脉溶栓";
              }) != -1
            ) {
              return false;
            } else {
              return true;
            }
          }
          if (type == "2" || type == "1") {
            if (
              this.queryParams.param.treatmentTypes.findIndex((item) => {
                return item == "AIS介入再通";
              }) != -1
            ) {
              return false;
            } else {
              return true;
            }
          }
          if (
            type == "3" ||
            type == "4" ||
            type == "5" ||
            type == "6" ||
            type == "7"
          ) {
            if (
              this.queryParams.param.treatmentTypes.findIndex((item) => {
                return item == "脑出血";
              }) != -1
            ) {
              return false;
            } else {
              return true;
            }
          }
          if (type == "8" || type == "9" || type == "6") {
            if (
              this.queryParams.param.treatmentTypes.findIndex((item) => {
                return item == "颅内动脉瘤";
              }) != -1
            ) {
              return false;
            } else {
              return true;
            }
          }
          if (type == "10" || type == "11" || type == "12" || type == "6") {
            if (
              this.queryParams.param.treatmentTypes.findIndex((item) => {
                return item == "CES/CAS";
              }) != -1
            ) {
              return false;
            } else {
              return true;
            }
          }
        } else {
          return true;
        }
      },
      // 搜索事件
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      // 重置事件
      resetQuery() {
        this.dataList = [];
        this.total = 0;
        this.queryParams.pageNum = 1;
        this.queryParams.pageSize = 10;
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 获取数据列表
      getList() {
        this.loading = true;
        const param = {
          ...this.queryParams
        };
        // if (param.param.zzbm && param.param.zzbm.length > 0) {
        //   param.param.zzmc = param.param.zzbm.join();
        // } else {
        //   param.param.zzmc = "";
        // }
        queryArchives(param).then((response) => {
          this.dataList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      // 列表选中事件
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.selectionData = [...selection];
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      // 新增急救档案
      handleAdd() {
        this.title = "新增急救档案";
        this.addDialog = true;
      },
      // 新增/修改弹框提交事件
      submitForm() {
        const param = {
          ...this.addForm
        };
        console.log("param: ", param);
        console.log("this.recordDtoList: ", this.recordDtoList);
        // param.recordDtoList = [...this.recordDtoList]
        let recordDtoList = [];
        for (let i = 0; i < this.recordDtoList.length; i++) {
          const item = this.recordDtoList[i];
          recordDtoList.push({
            code: item.code,
            answer: item.answer,
          });
        }
        for (let key in param.otherRecord) {
          recordDtoList.push({
            code: key,
            answer: param.otherRecord[key],
          });
        }
        param.recordDtoList = [...recordDtoList];
        param.type = this.queryParams.param.type;
        if (param.id) {
          // 修改
          updateArchives(param).then((res) => {
            this.$message.success("修改成功");
            this.cancel();
            this.handleQuery();
          });
        } else {
          // 新增
          insertArchives(param).then((res) => {
            this.$message.success("新增成功");
            this.cancel();
            this.handleQuery();
          });
        }
      },
      // 新增/修改弹框取消事件
      cancel() {
        this.resetForm("addForm");
        this.addDialog = false;
      },
      // 查看详情
      handleDetails(row) {
        const id = row.id;
        const type = this.queryParams.param.type;
        this.$router.push({
          path: "/data/archivesDetails",
          query: {
            id,
            type,
          },
        });
      },
      // 修改急救档案
      handleEdit(row) {
        this.title = "修改急救档案";
        // const data = row.id ? row : this.selectionData[0];
        // this.addForm = {
        //   ...data,
        // };
        // this.addDialog = true;
        const data = row.id ? row : this.selectionData[0];
        this.getDataDetails(data.id);
      },
      // 获取需要修改的档案的基础信息
      getDataDetails(id) {
        let addForm = {};
        const params = {
          pageNum: 1,
          pageSize: 1,
          param: {
            id,
            codeList: [...this.codeList],
            type: "1", // 档案类型(0:筛查； 1:急救； 2:治疗； 3:康复)
          },
        };
        const params1 = {
          pageNum: 1,
          pageSize: 1,
          param: {
            id,
            codeList: [
              "JBXX-FIRSTTIME", // 急救发生时间
              "JBXX-FIRSTAIDSCPOPE", // 急救范围
              "ZLLX-TYPE", // 治疗类型
              "JBXX-MZH", // 门/急诊号 默认传空字符串
              "JBXX-CZYS-NO", // 卒中医生编号 默认传空字符串
            ],
            type: "1", // 档案类型(0:筛查； 1:急救； 2:治疗； 3:康复)
          },
        };
        queryArchives(params).then((res) => {
          console.log("res: ", res);
          addForm = {
            ...res.data.list[0],
            recordDtoList: [...res.data.list[0].recordVoList],
          };
          // console.log("this.addForm111: ", this.addForm);
          // this.addDialog = true;
          queryArchives(params1).then((res) => {
            addForm = {
              ...addForm,
              otherRecord: {
                "JBXX-FIRSTTIME": res.data.list[0].recordVoList.find((item) => {
                  return item.code == "JBXX-FIRSTTIME";
                }).answer, // 急救发生时间
                "JBXX-FIRSTAIDSCPOPE": res.data.list[0].recordVoList.find(
                  (item) => {
                    return item.code == "JBXX-FIRSTAIDSCPOPE";
                  }
                ).answer, // 急救范围
                "ZLLX-TYPE": res.data.list[0].recordVoList.find((item) => {
                  return item.code == "ZLLX-TYPE";
                }).answer, // 治疗类型
                "JBXX-MZH": res.data.list[0].recordVoList.find((item) => {
                  return item.code == "JBXX-MZH";
                }).answer, // 门/急诊号 默认传空字符串
                "JBXX-CZYS-NO": res.data.list[0].recordVoList.find((item) => {
                  return item.code == "JBXX-CZYS-NO";
                }).answer, // 卒中医生编号 默认传空字符串
              },
            };
            console.log("this.addForm111: ", addForm);
            this.addForm = {
              ...addForm
            };
            this.addDialog = true;
          });
        });
      },
      // 删除急救档案
      handleDelete(row) {
        const idList = row.id ? [row.id] : [...this.ids];
        this.$modal
          .confirm("是否确认删除当前选择的档案？")
          .then(function() {
            // 删除
            return deleteArchives({
              idList
            });
          })
          .then(() => {
            this.$message.success("删除成功");
            this.handleQuery();
          })
          .catch(() => {});
      },
      // 导出
      handleExport() {
        // const params = { ...this.queryParams };
        const idList = [...this.ids];
        this.$modal.confirm("是否确认导出当前选中的档案数据？").then(() => {
          exportZl({
              idList
            })
            .then((res) => {
              // const url = window.URL.createObjectURL(new Blob([res]));
              const blob = new Blob([res]);
              this.$download.saveAs(blob, "急救档案数据.xlsx");
              this.$message.success("导出成功");
            })
            .catch((error) => {
              this.$message.success("下载Excel失败:", error);
              console.error("下载Excel失败:", error);
            });
        });
      },
    },
  };
</script>
